import { computed, createApp, toRaw } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { useHomeStore } from './stores/home'
import PanelHead from './components/panelHead.vue'

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

const pinia = createPinia()
// 1.添加持久化插件
pinia.use(piniaPluginPersistedstate)

// store挂载
app.use(pinia)

const homeStore = useHomeStore()
const routerList = computed(() => homeStore.routerList)

if (homeStore.routerList && homeStore.routerList.length > 0) {
  homeStore.dynamicMenu(routerList.value)
  toRaw(routerList.value).forEach(item => {
    router.addRoute('main', item)
  })
}

// 路由挂载
app.use(router)

app.component('PanelHead', PanelHead)
app.mount('#app')
